<html>
<head>
<title>Ocen nas</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function altRows(id){
	if(document.getElementsByTagName){  
		
		var table = document.getElementById(id);  
		var rows = table.getElementsByTagName("tr"); 
		 
		for(i = 0; i < rows.length; i++){          
			if(i % 3 == 0){
				rows[i].className = "evenrowcolor";
			}else{
				rows[i].className = "oddrowcolor";
			}      
		}
	}
}
window.onload=function(){
	altRows('alternatecolor');
}
</script>
<link href="table.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php 
echo "<center>";
	include ('detect.php');
	if (!isset($_SESSION)) session_start();
	if(kto() == 1) {
		include ('laczenie_baza.php');
		$email = $_SESSION['zalogowany'];
		$query = "SELECT ID FROM user WHERE email = '$email'";
		$result = mysql_query($query);
		$r = mysql_fetch_row($result);
		
		$query = "SELECT * FROM message WHERE ID_User = '$r[0]'";
		$result = mysql_query($query);
		$p = mysql_fetch_row($result);
		if ($p[0]) {
			echo "<h2>Już oceniałeś naszą przychodnię, szanowny panie pacjencie!</h2>";
			
		}
		else {
			include ('ocen_form.php');
		}
	}
	else {
		echo "<h2><i>Nie jesteś zalogowany na pacjenta!</i></h2>";
		include ("index.php");
	}
	
	$wylicz = "SELECT COUNT(ID) FROM message";
	$res = mysql_query($wylicz);
	$t = mysql_fetch_row($res);
	$i =0;
	for($i=0;$i<$t[0];$i++) {
		$query = "SELECT * FROM message";
		$result = mysql_query($query);
		mysql_data_seek($result, $i);
		$r = mysql_fetch_row($result);
		$j = 0;
		foreach ($r as $a)
			$tablica[$i][$j++] = $a." ";
	}
?>
<br><br>
<table border="2" width='50%' class="altrowstable" id="alternatecolor">
<?php 

if(isSet($tablica))
echo "Wystawione opinie :<br>";
for($i=0;$i<$t[0];$i++) {
	echo "<th>Opinia z dnia "."<font color='green'>[".$tablica[$i][4]."]</font>"."<font color='blue'> [".$tablica[$i][5]."]</font>&nbsp;&nbsp;&nbsp;&nbsp; Ocena: ".$tablica[$i][6]."</th>";
echo "<tr>";
echo "<td>".$tablica[$i][2]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right'>Przez: <b><i>".$tablica[$i][3]."</i></b></td>";
echo "</tr>";
}

?>
</table>
<?php 
$suma = 0;
for($i=0;$i<$t[0];$i++) {
	$suma += $tablica[$i][6];
}
if($i!=0) {
$avg = $suma/$i;
echo "<h3>Średnia ocen: $avg </h3><br>";
}
?>
<a href="index.php">Powrót do strony głównej</a>
</center>
</body>
</html>
